package com.hngy.xpq.appthemedemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    Button qh;
    TextView text001;
    SharedPreferences init;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        init();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        onclick();
    }

    private void init() {
        init = super.getSharedPreferences("init", MODE_PRIVATE);
        if ("red".equals(init.getString("theme", ""))){  // 判断当前风格是什么
            setTheme(R.style.AppThemeRed);
        } else if ("blue".equals(init.getString("theme", ""))) {
            setTheme(R.style.AppThemeBlue);
        } else if ("yellow".equals(init.getString("theme", ""))) {
            setTheme(R.style.AppThemeYellow);
        } else if ("mr".equals(init.getString("theme", ""))) {
            setTheme(R.style.AppTheme);
        }
    }

    private void onclick() {
        qh = findViewById(R.id.qh);
        text001 = findViewById(R.id.text001);
        qh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, QhThemeActivity.class);
                startActivity(intent);
            }
        });
    }
}